package collection;

import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;

import java.util.*;

/**
 * Created by chenxin on 2017/7/14.
 */
public class SetTest {
    public static void main(String[] args) {

//        Set<Integer> set = new HashSet<>();
//        set.add(1);
//
//        Set<Integer> b = Collections.unmodifiableSet(set);
//
//        set.add(2);
//
////        b.add(1);
//
//        System.out.println(b);
//
//        testSet();
//
//        removeTest();
//
//        removeEmptyTest();

        String as = "12189439,12217590,11308253,674779,12226248,12204969,12224204,12205600,12219328,11768232,2768150,9681516,10567333,10636382,11790400,2986159,3850325,674793,741985,7745703,11114060,12223250,12223248,12223255,12223252,11103782,12223253,12222952,10878966,12222953,11603172,12223247,12222947,12222950,12222951,5175411,12222948,11977941,12146650,12147691,12151126,12162035,8347768,9781379,10389694,10705027,10109114,10109115,10109112,10248382,10109113,6854732,10139839,10705030,10897536,10109116,10109106,10109107,10109105,10109110,11913368,10109111,10109108,11913370,10109109,7731265,5951586,10031318,11780334,10043640,10043643,10043645,10043647,10043646,10107120,10586315,10586317,10463475,10586319,10463473,10043639,10586320,10463470,10463469,10463467,10938579,10463465,8532212,10463464,10463462,12107972,8386560,9551897,9558040,9558042,9558044,9113630,7143669,9654281,9654280,19001885697,7872714,7282908,9578535,11708430,9957418,11051030,11710580,11726969,10705023,10137725,10408048,10408049,10586197,10586201,9564264,10164326,8241280,9558124,7872888,7561595,11383220,11383219,11936144,4716909,10750344,7870792,7919948,4716914,10531221,4716913,11110815,10475999,9525713,11962868,8395203,5597457,8395205,5962047,8055069,11045338,8493560,10711328,11927858,8491268,10713395,10043656,7963116,6025676,10043649,10043651,10043650,10043653,10043655,10139960,2767245,8466733,8458540,11802887,19001814313,10826011,10789146,9990490,9990491,8032683,6545798,6545796,10834254,7420289,10946901,10946898,11913893,11913894,10834608,7135817,5194341,4717162,7950924,10635935,9880279,10830560,9880286,11965180,9880284,10832622,9401028,9880285,9880282,9880283,10791658,9880281,10226373,10181313,10304192,8487648,9444083,8188432,10859209,7741977,9880290,9880288,9880289,10830556,10830558,3897920,11995848,10830554,19001741036,10238492,10238493,10238494,10238489,10238491,10889775,10238485,10238486,5860050,10238480,10238481,10238482,10238483,6802164,10840627,10521147,10621502,10521149,10521151,7445201,11637267,7445203,8495650,11637270,8495657,7107280,7606986,11020905,11211369,11020907,11020908,9204298,11020910,10984033,11020911,11842175,10093137,11020900,8174257,9626207,11020903,9525824,10410575,10410573,10410570,10093135,8462935,11020912,11020913,11020914,5411464,11020915,11020916,11020917,11020918,11020919,5628596,10521154,10521155,10521156,10521158,10521159,10521160,10091120,10091122,9976436,9443964,12098134,10091113,10091112,10091115,10091114,10109545,10091117,10091119,11838019,10091118,10699353,10091107,7709326,10091106,10091109,11135572,10091108,10091111,10766939,10091110,9350028,11768761,7816060,5335873,10621872,11963299,9534345,10840964,11269000,10079153,5884784,10697608,11268999,6632265,11268996,10349490,10349484,10349486,7951181,6148971,10492823,12049294,9943977,10685340,7924530,7924533,5409587,11955157,7174926,9729009,10755018,5124927,10638288,5124924,5124925,10875856,6972390,10750780,10816316,11076361,11739921,11076363,11875094,11076362,11076365,6708163,11076367,8461101,10099511,7953367,6708169,11758337,5331946,10521372,10826520,10521374,5124996,10347345,5124995,10347347,12006247,10347341,10347340,10347343,10347342,10347339,10347338,10793848,11615057,6552449,6052788,1020897,10949459,10830680,9718930,5332032,5332038,10056832,11963565,11009212,8365156,9610377,10751160,9888959,11318400,10099895,10876043,9387192,7662668,11850893,11850894,11850895,11850889,10493085,11850890,10945767,10945766,8553668,10945772,10945771,10945770,10945768,10755318,9868485,10603766,10751228,7590955,19001786567,9710799,5331981,11977941,11228360,9641206,9866490,6542351,11844825,6542350,11807943,9774316,11031763,19001878552,19001878551,11832383,9620482,10642482,6063309,10642486,11433017,10642485,10642490,9939983,10642491,9939982,10642492,10849285,11791376,10552324,11445250,11445251,9610274,9610279,9610277,12053517,9987152,7613624,7826619,9987156,8060086,9987157,9987159,9987144,11318397,11318398,9987147,9987150,7924901,11893853,11766875,10980431,10552392,10980430,11766873,10980428,10980427,11766877,5207200,10263656,10980434,6462612,10980433,10980432,10714202,10751070,10515548,12047799,12047796,6890862,4877634,7476606,12047801,4877636,11638206,4877637,11642273,7859557,12060079,9606536,11021749,7476591,8363361,6890871,11376050,6890870,10769799,9964989,6559052,4357480,11758976,9827746,9934253,10841568,11013604,9293274,11017713,10763775,10702275,12096989,12096991,8379670,7925000,7918859,7939577,9919764,10165528,10165535,10165534,10165533,10165532,10165522,7939571,11840831,7189990,10165520,10165526,9209091,10165524,11001140,9882880,10798396,12023086,10798392,10798393,10798394,6544892,10945798,10829063,3890591,3890590,9827632,10829069,10009906,10829071,10048821,9938235,9938233,10829066,9938232,8680757,10165538,9827631,11838836,10532192,10702178,10904932,1766873,10904933,9551189,10851683,10702180,9727324,9727325,8488267,9727326,10798447,9727327,6981028,9727323,11054457,10161480,10798448,6251912,5207446,19001903431,11015539,10642815,10906948,11195724,11025742,7996829,10435956,12119380,10364274,9475455,9872742,7476608,9872741,9872738,9872739,9295227,9633124,8351112,9872750,9872748,8502653,9872744,9872745,11200170,8492686,10843828,7761508,10895029,10895025,10899131,6545022,10518207,6540867,6540871,6540869,7949919,6540868,8492712,11411074,10837642,11570823,9828014,12000905,5223949,6544928,8103486,9635541,9744082,9512670,10389198,10837751,8457939,7587367,8457940,10098381,6540859,9610954,9610952,6540863,6540860,10747587,10747590,6544901,10088190,10747588,6544900,10747595,10747594,10747593,10747597,9993975,5686822,12029632,7937550,11411153,9631251,11021866,9631252,9631253,10759724,10298902,10184208,8349427,10475019,9631247,10833467,19001807418,19001807419,10876430,10743319,9975342,10692116,5867233,11994743,10290780,10290782,10290777,10290779,10747492,10290775,9743966,9743961,9827931,9743963,11839074,19001809472,9872969,19001879161,6067889,5232289,10640983,10290789,10290788,11249232,10290784,10290787,6250144,10407838,10948524,10469262,9648011,10291077,12105633,10291079,8255335,10291078,10407810,12105637,11704236,10407809,12105626,12105629,11872144,12105630,10588054,7866177,9566124,12097528,10586083,11642869,10586086,10850254,11329501,11192286,11192287,10254309,8386558,7815155,9611030,9647894,8214523,11032354,11032355,11032356,9510685,11382560,7088097,11382562,11872033,11894573,8429336,9742094,11032328,7487442,11032329,8595234,11032330,11032331,10983172,11032332,11032333,11032334,11032335,9744189,11032322,11032323,11032325,11032326,11032327,11032336,11032337,11974412,11032340,11032341,11032342,10551137,9295681,11874145,12171105,12171104,10407807,8142750,10407804,10407805,10407803,11032398,11032399,10407801,10407799,10407797,11032390,10993503,11032400,7487370,11032401,11032402,4416451,11863476,9332229,453771,1450651,613639,374047,8550556,8493727,349476,4272364,1788852,6080997,4661012,12171105,12171104,11007226,674794,1940346,338037,3444547,8426949,4120298,469842,245185,674792,4410762,2749723,5331977,6540968,6578983,6694162,7090188,7282925,7924899,8025162,8040296,8098980,8349425,9206996,9336378,9508971,9513157,9548926,9619877,9638078,9645319,9651120,9744544,9773894,9975434,9975539,247769,3443347,2440865,8500163,5767375,1380064,311755,760836,1382292,715993,8505790,6263597,1320266,1979029,780615,1972648,6471510,1273343,469906,7441992,6512108,10587430,10595756,11028852,9694491,11895230,11870483,10521341,10452907,9814007,9859431,9309323,10858027,9572777,11983504,11501697,11048758,10073016,11674192,10380834,9561240,10662943,10765892,10794381,9664470,9173249,11501697,10380834,10521341,9776117,10794381,10858027,9173249,10667132,11595911,8707412,7742968,11633828,11733361,11525542,9694797,10883728,10394460,11922066,11964610,11033161,11572437,11288377,11069647,8890224,10948125,10575790,10304457,10757932,11449621,11339951,8857539,10541181,10344251,11038597,10905294,10600783,8787938,8280331,11629958,8338431,10979286,10293676,11351352,10751185,11862270,11490528,11572685,11010393,11444021,10108603,10146908,9139791,11864658,11606701,10765614,10034963,10135902,9139791,11592485,11351352,9704312,8280331,11115603,11105059,10905294,9927566,11444021,10757932,7371699,11595905,9776117,9822615,10689867,10109789,9139767,11038597,11054044,10120204,10416110,10718996,8670418,9224071,9681501,10940583,11674192,10662943,8338431,10600783,11395406,9417179,8787938,10979286,10757931,9754210,10847139,10858027,10858027,10829336,10875655,10690438,10146908,10108603,8888919,8431860,11514558,9173249,9591659,10751185,10280165,7921917,11020942,10878009,10794381,10541181,10749710,10875204,9504820,10415149,10215578,8400862,11053748,10380834,10582289,8857539,7573309,10121974,11040475,10405596,10595756,10409032,9466457,10765892,9694491,10569307,10755505,10989365,10802569,11339950,10218079,9814007,9621076,9322126,10130264,11048096,9845887,9664470,10073016,8410049,10425384,10878155,10735069,11812160,10514924,6820950,8485934,8794622,11444210,9729439,10052994,11606983,10576651,11219992,9013615,10878663,10457302,10438183,10538875,10940582,10579408,10175412,10662945,11595915,8229862,10751895,11632489,11069612,9966701,11538995,11521923,11280307,11194216,9213300,10737072,11169598,11106544,11270368,9811159,10905448,10586958,9928405,11241845,11449517,11559079,11634728,10847231,10981624,11104246,10090608,10136773,11104623,10708884,10070872,10553682,10133635,7623452,10283990,10786273,11369859,8063024,9643111,10577984,10511677,11104778,10053240,11664783,10797490,10037136,11477745,123455,1487581,5628008,236702,1554323,1723027,1714476,9593252,9600237,9631828,10054250,9950276,8745589,9396164,9076224,9958962,10457108,11135085,10794512,10486015,9979649,11634322,11720683,10696348,9973019,10139907,11115862,10140799,10469403,11182406,8653873,11336052,11577077,9693058,10426441,11114658,11449468,10277628,11335902,10877162,11576492,10595158,10379223,10794319,10690651,11054097,10400933,126382,11059544,2079793,5097261,9296575,10356109,7512027,7515579,4945999,11295019,10133034,10054409,1380069,616740,10669447,760837,616704,10997413,10459684,5875558,10210885,9264854,9154555,10745820,9804332,6009607,10847303,10173813,11438028,9343423,5350867,9934029,9102403,10703233,7607525,11271382,11037202,10975910,10284312,9601977,9900968,10342355,9561542,9090923,10067079,9484307,8393497,7934500,10162204,8147764,7651602,10459483,8526078,8630780,8879484,10335698,8957530,10294134,8030852,8373437,10881384,9872135,10289169,11172208,8023002,8034880,8430322,9827390,11149246,11077095,7753877,11077096,8360010,9505457,7904120,8792455,7887832,10335698,11039170,8110312,10278642,10873154,7751646,9224358,9524681,11040631,10294134,1520378,8630780,8879484,8957530,8526078,10294134,10335698,8390623,10393200,10585119,6822056,10669320,8155487,8256746,7537589,10520405,10669796,11026786,8684915,7935309,10342335,8413984,9706596,9005611,8361547,9951838,10995907,7934953,10394621,8943678,8843796,8146330,7135918,10133709,9066299,9135039,9664800,10998023,7961180,8373551,10973464,10896164,9775271,9721629,10520385,9719908,10815530,7931121,7167888,10097055,7893949,7958118,8022991,7545449,9006940,2083163,7226046,1591485,7482583,5729420,963321,1607564,2572247,311789,2292483,5335588,1711295,4018221,459724,876576,3871875,6479407,6406319,4680732,1630842,5416826,2028863,1958743,1958744,5221695,1701200,2675206,4968431,11037106,3080076,3080007,6043540,2822939,10064073,5537025,676635,1421356,676633,1421356,311789,2292483,5335588,1711295,4018221,459724,876576,3871875,6479407,6406319,4680732,1630842,5416826,2028863,1958743,1958744,5221695,1701200,2675206,4968431,11037106,2724029,9241602,586491,1916596,676637,8595577,1591485,7482583,9448553,8637954,5729420,9344811,2724029,7979904,3682435,6216424,5225373,9241602,1607564,963321,174674,586491,463536,3269118,940553,1916596,676637,676635,10479057,1421356,676633,9599216,7731326,7371528,7190048,2572247,8595577,8595016,7515263,529032,9344811,7979904,10479057,676633,9599216,8595016,7515263,940553,174674,463536,247442,736200,5767375,7660687,8748506,350430,5807459,311804,265102,7933074,616711,267685,311757,8431884,616706,7325715,311771,247769,616705,3788234,267656,1762063,4165954,4260187,4260252,4260355,4260365,4260368,4328483,4357038,4415900,5345639,5728977,5729450,5871684,6036144,6213996,6340476,6405343,6476762,6542197,6542198,6555230,6628527,6890866,6890867,7476710,7476711,7476725,7476727,7476728,7476730,7476731,7476733,7476735,7476737,7476814,7477777,7662664,7662669,7912195,7912202,8022706,8022714,8023334,8051014,8051015,8064455,8064457,8064458,8064459,8064460,8064461,8064462,8065662,8204635,8204636,8342676,8342677,8342679,8386559,8386566,8386569,8457937,8457951,8457961,8457962,8487823,8495644,8495647,8495649,8750693,8750694,8753212,8860239,8860241,8860243,9056063,9163131,1121060,1353886,1353887,1353889,1353891,1353893,1353898,1555411,1613943,1897961,1898014,1898015,1900558,1966020,1966021,1993409,3066440,3134517,3788227,3788228,3788229,3788230,3788231,3788232,3788233,3788235,3788236,3788237,3788238,3788239,3788240,3788241,3788264,3829291,3829292,3829293,3829294,3829295,3829297,3829298,3829299,3890575,3890578,3890579,3890582,3890585,3890587,3890589,3890594,3897763,3897881,3897931,3897952,4040360,4040361,4040362,4165874,4166085,4219760,4219917,4314697,4357125,4415901,4503727,4503728,4503730,4840880,4858450,4999189,5113760,5113772,5113783,5318297,5540989,5739810,5899320,6036215,6051980,6102740,6102767,6150194,6150239,6182220,6213736,6296988,6297037,6297066,6297096,6340470,6405341,6405342,6405792,6462611,6462613,6462614,6462615,6462791,6462792,6462888,6476761,6476763,6560792,6628525,6628526,6628528,6628529,6628643,6890856,6890857,6890858,6890859,6890860,6890861,6890863,6890864,6890865,6890868,6890869,6934887,7212052,7212053,7212054,7212056,7212058,7212059,7212060,7212061,7231606,7322772,7322773,7322774,7322775,7322776,7322777,7322778,7322779,7322780,7322831,7323267,7476593,7476595,7476596,7476598,7476599,7476601,7476602,7476604,7476610,7476612,7476613,7476615,7476713,7476714,7476717,7476719,7476720,7476722,7476723,7476812,7476813,7477775,7662652,7662653,7662654,7662656,7662657,7662658,7662659,7662660,7662661,7662662,7662663,7662665,7662666,7662667,7662670,7662671,7662672,7662746,7662747,7676240,7676242,7676243,7676517,7708490,7708494,7739256,7739258,7739260,7748561,7748562,7783192,7783194,7795191,7795194,7795196,7795963,7870793,7871428,7912196,7912197,7912198,7912199,7912200,7912201,7912203,7937551,7937552,7937553,7942730,7942732,7942734,7942735,7942737,7942854,7952734,7972709,7979435,7989523,8022704,8022708,8022710,8022712,8022716,8023329,8023331,8028645,8028647,8050083,8050669,8050671,8055278,8064456,8080551,8080552,8110842,8110843,8149022,8149023,8156187,8168766,8168767,8204637,8274608,8274610,8274611,8274612,8274613,8274615,8309537,8309541,8309543,8342678,8342680,8372372,8386561,8386562,8386563,8386564,8386568,8457938,8457942,8457943,8457945,8457946,8457948,8457949,8457952,8457953,8457955,8457956,8457958,8457960,8458541,8487815,8487816,8487817,8487818,8487819,8487820,8487821,8487822,8487824,8487825,8487826,8487827,8487828,8487946,8487947,8495634,8495635,8495636,8495637,8495638,8495639,8495640,8495641,8495642,8495643,8495645,8495646,8495648,8495651,8495652,8495653,8495654,8495655,8495656,8496880,8496881,8496882,8496883,8496884,8496885,8496886,8496887,8496889,8496890,8496891,8496892,8501008,8551809,8556363,8567063,8567064,8579049,8656408,8656412,8750692,8750696,8750697,8753210,8777087,8777088,8860236,8860237,8929413,8929414,8991277,9056056,9056057,9056059,9056066,9061413,9061415,9061417,9062854,9163128,9163130,9197172,9197174,9197175,9197176,9356168,9356170,9356172,9356175,9356281,9435779,9435780,9435782,9435783,9435785,9435786,9435787,9435788,9435789,9436493,311757,311772,8481680,311781,970962,8431884,4221774,267659,267640,267685,644740,606327,311799,311800,9572777,7660687,8748506";
        final List<String> list1 = Splitter.on(",").splitToList(as);
        Set<Long> a = new HashSet<>();
        for (String s : list1) {
            a.add(Long.parseLong(s));
        }

        String bs = "10567333,10802569,10940583,11308253,11540658,11546478,11768232,11790400,11974669,12189439,12204969,12205600,12217590,12219328,12224204,12226248,1380071,1380077,1380086,1380101,1380123,1380138,1601519,2038647,2768150,2841160,2967889,311740,311756,311790,311805,311811,3978521,4273388,5568028,616703,616708,616717,665774,674779,7921917,8481617,8608894,925301,9681516";
        final List<String> list2 = Splitter.on(",").splitToList(bs);
        Set<Long> b = new HashSet<>();
        for (String s : list2) {
            b.add(Long.parseLong(s));
        }
        diff(a, b);

    }

    /**
     * b-a
     * @param a
     * @param b
     */
    private static void diff(Set<Long> a, Set<Long> b) {
        final Sets.SetView<Long> difference = Sets.difference(b, a);
        System.out.println(difference);
        System.out.println(difference.size());
        StringBuilder stringBuilder = new StringBuilder();
        for (Long v : difference) {
            stringBuilder.append(v).append(",");
        }
        System.out.println(stringBuilder.toString());
    }


    private static void removeEmptyTest() {
        Collection<Long> allRidersList = new ArrayList<>();
        allRidersList.add(1L);
        allRidersList.add(2L);
        allRidersList.add(3L);

        allRidersList.removeAll(new HashSet<>());
        System.out.println("after remove empty " + allRidersList);
    }


    private static void removeTest() {
        List<Long> allRidersList = new ArrayList<>();
        allRidersList.add(1L);
        allRidersList.add(2L);
        allRidersList.add(3L);

        List<Long> all = new ArrayList<>();
        all.add(1L);
        all.add(3L);

        allRidersList.removeAll(all);
        System.out.println("after remove" + allRidersList);

    }

    private static void testSet() {
        List<Long> allRidersList = new ArrayList<>();
        allRidersList.add(1L);
        allRidersList.add(1L);
        System.out.println(allRidersList);
        List<Long> uniqueRiders = ImmutableSet.copyOf(allRidersList).asList();
        System.out.println(uniqueRiders);

        List<Long> uniqueRiderIds2 = new ArrayList<>(new HashSet<>(allRidersList));
        System.out.println(uniqueRiderIds2);
    }
}
